# coding: utf-8
# Author: legend
# @Time： 2021/3/8 下午1:48
import hashlib

from rest_framework.decorators import action
from rest_framework.mixins import CreateModelMixin, ListModelMixin, RetrieveModelMixin
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet

from apps.test.models import Interviewer
from apps.test.serializers.interviewer import InterviewerSerializer


class InterviewerViewSet(GenericViewSet, CreateModelMixin, ListModelMixin, RetrieveModelMixin):
    queryset = Interviewer.objects.all()
    serializer_class = InterviewerSerializer

    @action(methods=['post'], detail=False)
    def login(self, request):
        data = request.data
        password = data.get('password')
        m = hashlib.md5()
        m.update('superadmin'.encode())
        if data.get('user') == 'admin' and password == 'superadmin':
            return Response("登录成功！")
        else:
            return Response("用户名或密码错误", status=400)
